package ua.edu.nuos.jeetraining2012.automator.core.vo.message;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Timur Yarosh
 *         Date: 04.06.13
 *         Time: 0:45
 */
public class MessageDestination {
    private List<String> addressees;
    private int type;

    public MessageDestination() {
        addressees = new ArrayList<String>();
    }

    public List<String> getAddressees() {
        return addressees;
    }

    public boolean addAddressee(String addressee) {
        return addressees.add(addressee);
    }

    public boolean removeAddressee(String addressee) {
        return addressees.remove(addressee);
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public InternetAddress[] toAddress() {
        try {
            String[] strings = addressees.toArray(new String[0]);
            InternetAddress[] internetAddresses = new InternetAddress[strings.length];
            for (int i = 0; i < strings.length; i++) {
                internetAddresses[i] = new InternetAddress(strings[i]);
            }
            return internetAddresses;
        } catch (AddressException e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
}
